

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-15
 * Time: 15:31
 */
package thread;
import java.util.Scanner;
public class demo14{
    private  static int flag = 0;
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            while(flag == 0) {
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1 线程结束");
        });

        Thread t2 = new Thread(()->{
            System.out.println("请输入flag的值:");
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();
            System.out.println("t2 结束");
        });

        t1.start();
        t2.start();
    }
}